package com.ruoyi.web.controller.businessSettings;

import java.util.List;
import java.util.stream.Collectors;
import com.ruoyi.system.domain.SelfBookingSettings;
import com.ruoyi.system.domain.StoreSettings;
import com.ruoyi.system.domain.vo.TraditionalBookingSettingsVO;
import com.ruoyi.system.service.ISelfBookingSettingsService;
import com.ruoyi.system.service.IStoreSettingsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 传统预订设置 Controller
 *
 * @author ruoyi
 * @date 2025-05-16
 */
@Api(tags="传统预订设置")
@RestController
@RequestMapping("/system/traditionalBookingSettings")
public class TraditionalBookingSettingsController extends BaseController
{

    @Autowired
    private IStoreSettingsService storeSettingsService;

    @Autowired
    private ISelfBookingSettingsService selfBookingSettingsService;

    /**
     * 查询传统预订设置列表
     */
    @ApiOperation("查询传统预订设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();

        List<StoreSettings> entityList = storeSettingsService.selectStoreSettingsListByName(storeName);

        List<TraditionalBookingSettingsVO> voList = entityList.stream()
                .map(entity -> {
                    TraditionalBookingSettingsVO vo = new TraditionalBookingSettingsVO();
                    vo.setId(entity.getId());
                    vo.setStoreId(entity.getStoreId());
                    vo.setStoreName(entity.getStoreName());

                    // 查询自助预订设置表中的字段
                    SelfBookingSettings bookingSettings = selfBookingSettingsService.selectByStoreId(entity.getStoreId());
                    if (bookingSettings != null) {
                        vo.setMiniProgramBooking(bookingSettings.getMiniProgramBookingEnabled());
                    }

                    return vo;
                })
                .collect(Collectors.toList());

        return getDataTable(voList);
    }

}
